package client;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Dialog.ModalityType;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import javax.print.attribute.standard.Sides;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import server.PersonInterface;
import server.StaffInterface;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class WorkEffect_GUI extends JDialog {

	private final JPanel contentPanel = new JPanel();

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		try {
			WorkEffect_GUI dialog = new WorkEffect_GUI();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 * @throws NotBoundException 
	 * @throws RemoteException 
	 * @throws MalformedURLException 
	 */
	public WorkEffect_GUI() throws MalformedURLException, RemoteException, NotBoundException {
		setTitle("\u672C\u6B21\u5DE5\u4F5C\u6548\u76CA");
		setModalityType(ModalityType.APPLICATION_MODAL);
		setBounds(100, 100, 450, 300);
		setModalityType(ModalityType.APPLICATION_MODAL);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		JLabel label = new JLabel("\u83B7\u5F97\u85AA\u6C34\uFF1A");
		label.setBounds(74, 38, 93, 15);
		contentPanel.add(label);
		
		JLabel label_1 = new JLabel("\u6D88\u8017\u4F53\u529B\u503C\uFF1A");
		label_1.setBounds(74, 71, 100, 15);
		contentPanel.add(label_1);
		
		JLabel label_2 = new JLabel("\u6D88\u8017\u6109\u60A6\u503C\uFF1A");
		label_2.setBounds(74, 107, 100, 15);
		contentPanel.add(label_2);
		
		JLabel label_3 = new JLabel("\u83B7\u5F97\u7ECF\u9A8C\uFF1A");
		label_3.setBounds(74, 145, 100, 15);
		contentPanel.add(label_3);
		
		
		Person per=new Person();
		int pid=per.getPID();
		Configuration config=new Configuration();
		String rmiAddress=config.getRmiAddress();
		PersonInterface PI=(PersonInterface) Naming.lookup(rmiAddress+"Person");
		StaffInterface SI=(StaffInterface) Naming.lookup(rmiAddress+"Staff");
		
		try
		{
			int comId=PI.getComID(pid);
			String pjob=PI.getJob(pid);
		
			
		if(PI.cashChanges(pid, SI.getSalary(comId, pjob), '+'))
		{
		JLabel label_4 = new JLabel(""+(SI.getSalary(comId, pjob)));
		label_4.setToolTipText("\u663E\u793A\u85AA\u6C34");
		label_4.setBounds(194, 38, 54, 15);
		contentPanel.add(label_4);
		}
		if(PI.hpChanges(pid,SI.getConsumHp(comId, pjob),'-'))
		{		
		JLabel lblNewLabel = new JLabel(String.valueOf(SI.getConsumHp(comId, pjob)));
		lblNewLabel.setToolTipText("\u663E\u793A\u6D88\u8017\u4F53\u529B\u503C");
		lblNewLabel.setBounds(194, 71, 54, 15);
		contentPanel.add(lblNewLabel);
		}
		else{
			JOptionPane.showMessageDialog(null, "体力透支！！");
			dispose();
		}
		if(PI.hapChanges(pid,SI.getConsumHap(comId,pjob),'-'))
			{
	
		JLabel lblNewLabel_1 = new JLabel(String.valueOf(SI.getConsumHap(comId, pjob)));
		lblNewLabel_1.setToolTipText("\u663E\u793A\u6D88\u8017\u6109\u60A6\u503C");
		lblNewLabel_1.setBounds(194, 107, 54, 15);
		contentPanel.add(lblNewLabel_1);
			}
		else
		{
			JOptionPane.showMessageDialog(null, "愉悦值不足！！");
		}
		
		if(PI.expChanges(pid,SI.getExp(comId, pjob),'+'))
		{
		JLabel lblNewLabel_2 = new JLabel(String.valueOf(SI.getExp(comId, pjob)));
		lblNewLabel_2.setToolTipText("\u663E\u793A\u83B7\u5F97\u7ECF\u9A8C\u503C");
		lblNewLabel_2.setBounds(194, 145, 54, 15);
		contentPanel.add(lblNewLabel_2);
		
		if(SI.isPromoted(PI.getExp(pid), SI.getUpExp(comId,pjob)))
		{
			
			if(PI.apply(pid, SI.getPost(comId, SI.getLevel(comId, pjob)+1)))
				{
				JOptionPane.showMessageDialog(null, "恭喜您升职了！！");
				}
		}
		}
	
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		JButton btnNewButton = new JButton("下班");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		btnNewButton.setBounds(289, 203, 93, 23);
		contentPanel.add(btnNewButton);

	}
}
